package com.chenfan.filestore.disruptor.translator;

import com.chenfan.filestore.model.dto.ParseExcelDTO;
import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;

public class LongEventProducerWithTranslator {

    //一个translator可以看做一个事件初始化器，publicEvent方法会调用它
    private static final EventTranslatorOneArg<ParseExcelDTO, ParseExcelDTO> TRANSLATOR =
            (event, sequence, data) -> {
                event.setTask(data.getTask());
                event.setBatchImportTemplate(data.getBatchImportTemplate());
                event.setSendToBusinessList(data.getSendToBusinessList());
                event.setResultList(data.getResultList());
            };

    private final RingBuffer<ParseExcelDTO> ringBuffer;

    public LongEventProducerWithTranslator(RingBuffer<ParseExcelDTO> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void produce(ParseExcelDTO data) {
        ringBuffer.publishEvent(TRANSLATOR, data);
    }
}
